const toString = Object.prototype.toString

export const is = (val: unknown, type: string) =>{
    return toString.call(val) === `[object ${type}]`
}

export const isString = (val: unknown): val is string => {
    return is(val, 'String')
}

export const isFunction = (val: unknown): val is Function => {
    return typeof val === 'function'
}

export const isBoolean = (val: unknown): val is boolean => {
    return is(val, 'Boolean')
}

export const isRegExp = (val: unknown): val is RegExp => {
    return is(val, 'RegExp')
}
export const isObject = (val: unknown): val is Record<any, any> => {
    return val !== null && is(val, 'Object')
}
export const isPromise = <T = any>(val: unknown): val is Promise<T> => {
    return is(val, 'Promise') && isObject(val) && isFunction(val.then) && isFunction(val.catch)
}

export const isArray = (val: any): val is Array<any> => {
    return val && Array.isArray(val)
}